package com.shop.coupon.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.common.core.domain.Result;
import com.shop.common.security.utils.SecurityUtils;
import com.shop.coupon.domain.vo.CouponHistoryVo;
import com.shop.coupon.mapper.CouponHistoryVoMapper;
import com.shop.coupon.service.CouponHistoryVoService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CouponHistoryVoServiceImpl extends ServiceImpl<CouponHistoryVoMapper , CouponHistoryVo> implements CouponHistoryVoService {

    private final CouponHistoryVoMapper couponHistoryVoMapper;

    public CouponHistoryVoServiceImpl(CouponHistoryVoMapper couponHistoryVoMapper) {
        this.couponHistoryVoMapper = couponHistoryVoMapper;
    }




    /**
     * 查询当前用户的优惠券列表
     * @param couponHistoryVo
     * @return
     */
    @Override
        public Result couponUserSelect(CouponHistoryVo couponHistoryVo) {
        Long userId = SecurityUtils.getUserId();
        couponHistoryVo.setMemberId(userId);
        List<CouponHistoryVo> userSelect = couponHistoryVoMapper.couponUserSelect(couponHistoryVo.getMemberId());
        return Result.success(userSelect);

    }

    /**
     * 已使用的优惠券列表
     * @param couponHistoryVo
     * @return
     */
    @Override
    public Result couponUserSelectUse(CouponHistoryVo couponHistoryVo) {
        Long userId = SecurityUtils.getUserId();
        couponHistoryVo.setMemberId(userId);
        List<CouponHistoryVo> userSelect = couponHistoryVoMapper.couponUserSelectUse(couponHistoryVo.getMemberId());
        return Result.success(userSelect);
    }

    //已过期的优惠券列表
    @Override
    public Result couponUserSelectExpired(CouponHistoryVo couponHistoryVo) {
        Long userId = SecurityUtils.getUserId();
        couponHistoryVo.setMemberId(userId);
        List<CouponHistoryVo> userSelect = couponHistoryVoMapper.couponUserSelectExpired(couponHistoryVo.getMemberId());
        return Result.success(userSelect);
    }

    /**
     * 当前用户优惠券删除
     * @param memberId
     * @return
     */
    @Override
    public Result couponUserDelete(Long memberId) {
        int byId = baseMapper.deleteById(memberId);
        return Result.success(byId);
    }
}
